/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dep;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JTextArea;

/**
 *
 * @author xyBerWise
 */
public class DataBase {

    private Connection conn3ction = null;
    private ResultSet res = null;
    private int i = 0;
    private static DataBase _INSTANCE = null;

    private DataBase() {
    }

    public static synchronized DataBase getInstence() {
        if (_INSTANCE == null) {
            _INSTANCE = new DataBase();
        }
        return _INSTANCE;
    }

    public Connection sqliteConnect() {
        try {
            if (conn3ction == null || conn3ction.isClosed()) {
                Class.forName("org.sqlite.JDBC");
                conn3ction = DriverManager.getConnection("jdbc:sqlite:xbe8.xbw");
            }
        } catch (ClassNotFoundException e) {
            return null;
        } catch (SQLException e) {
            return null;
        } finally {
            try {
                if (conn3ction == null) {
                    conn3ction.close();
                }
            } catch (SQLException e) {
            }
        }
        return conn3ction;
    }

    public int DatatoText(String Word, JTextArea jt) {
        try {
            Statement stat = sqliteConnect().createStatement();
            res = stat.executeQuery("SELECT x80c8167c4b FROM x140c812296b WHERE x80c8144cc8 = '" + Word + "';");

            while (res.next()) {
                String trans = "";
                for (i = 0; i < res.getString("x80c8167c4b").split("\\|").length; i++) {
                    trans += res.getString("x80c8167c4b").split("\\|")[i] + "\n";
                }

                jt.setText(trans);

            }
        } catch (SQLException e) {
            try {
                res.close();
                conn3ction.close();
            } catch (SQLException ex) {
            }
        }
        try {
            res.close();
            conn3ction.close();
        } catch (SQLException ex) {
        }

        return i;
    }
}
